﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;

public partial class Default2 : System.Web.UI.Page
{
    TblMenuDAO menuDAO = new TblMenuDAO(Global.CONNECTION_STRING);
    TblMenuItemDAO itemMenuDAO = new TblMenuItemDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadParenMenu();
        }
    }


    private void LoadParenMenu()
    {
        reParentMenu.DataSource = menuDAO.GetAll();
        reParentMenu.DataBind();
    }
    protected void reParentMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
           e.Item.ItemType == ListItemType.AlternatingItem)
        {
            //int idCus = ((TblCustomers)Session[Global.SESSION_LOGGED_USER]).CustomerIndex;
            Repeater reChildMenu = (Repeater)e.Item.FindControl("reChildMenu");
            HiddenField hidIDMenuP = (HiddenField)e.Item.FindControl("hidIDMenuP");
            hidIDMenuP.Value = DataBinder.Eval(e.Item.DataItem, "ID").ToString();

           // DataTable dtParentMenu = ParentMenuDAO.GetParentMenuAll(idCus);
           // Lấy menu Cha

            DataTable menuCha = menuDAO.GetAll();

            string id = hidIDMenuP.Value;
            string idMenu = Request.QueryString["id"];
            if (reChildMenu != null)
            {

                reChildMenu.DataSource = itemMenuDAO.GetMenuItem_ByIDMenu(Global.ConvertToInt(id));
                reChildMenu.DataBind();
            }

        }
    }
}
